package com.gy.smart.handle;

import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gy.smart.R;
import com.gy.smart.base.BaseFragment;
import com.gy.smart.handle.bean.HandleDetailBean;
import com.gy.smart.handle.util.HandleDetailManager;
import com.gy.smart.home.HelpMapActivity;
import com.gy.smart.util.AnimUtil;

/**
 * Created by 高岳 on 2017/1/5.
 * Describe:办事基本信息
 */
public class HandleInforFragment extends BaseFragment implements HandleDetailManager.IHandleDetailListener {

    private TextView tvTitle, tvClass, tvName, tvCode, tvDepartment;
    private LinearLayout llLoc, llAskPhone, llComplaintPhone, llImg;
    private HandleDetailBean detailBean;

    @Override
    protected View setView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.fragment_handle_info, null);
        hidenTop();
        return view;
    }

    @Override
    protected void initView() {
        tvTitle = (TextView) _rootView.findViewById(R.id.fg_handle_info_tv_title);
        tvClass = (TextView) _rootView.findViewById(R.id.fg_handle_info_tv_type);
        tvName = (TextView) _rootView.findViewById(R.id.fg_handle_info_tv_name);
        tvCode = (TextView) _rootView.findViewById(R.id.fg_handle_info_tv_code);
        tvDepartment = (TextView) _rootView.findViewById(R.id.fg_handle_info_tv_department);
        llLoc = (LinearLayout) _rootView.findViewById(R.id.fg_handle_info_ll_loc);
        llAskPhone = (LinearLayout) _rootView.findViewById(R.id.fg_handle_info_ll_ask_phone);
        llComplaintPhone = (LinearLayout) _rootView.findViewById(R.id.fg_handle_info_ll_complaint_phone);
        llImg = (LinearLayout) _rootView.findViewById(R.id.fg_handle_info_ll_img);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {
        super.setListener();
        llLoc.setOnClickListener(this);
        llAskPhone.setOnClickListener(this);
        llComplaintPhone.setOnClickListener(this);
        llImg.setOnClickListener(this);
        HandleDetailManager.getInstance().addListener(this);
    }

    @Override
    protected void fillData() {
        super.fillData();

    }

    @Override
    public void doClick(View v) {
        super.doClick(v);
        Intent intent;
        switch (v.getId()) {
            case R.id.fg_handle_info_ll_loc:
                intent = new Intent(mContext, HelpMapActivity.class);
                intent.putExtra("endLat", 40.226373);
                intent.putExtra("endLong", 116.237824);
                intent.putExtra("address",detailBean.base.accept_address + "");
                intent.putExtra("title",  "");
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(getActivity());
                break;
            case R.id.fg_handle_info_ll_ask_phone:
                intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + detailBean.base.hotline));
                startActivity(intent);
                break;
            case R.id.fg_handle_info_ll_complaint_phone:
                intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + detailBean.base.complaints_hotline));
                startActivity(intent);
                break;
            case R.id.fg_handle_info_ll_img:
                intent = new Intent(mContext,ShowPicActivity.class);
                intent.putExtra("imgurl",detailBean.base.flow_chart);
                startActivity(intent);
                AnimUtil.pushLeftInAndOut(getActivity());
                break;
        }
    }

    @Override
    public void handleDetailChange(HandleDetailBean detailBean) {
        this.detailBean = detailBean;
        if (detailBean != null && detailBean.base != null) {
            setViews();
        }
    }

    private void setViews() {
        tvClass.setText("职权类别：" + detailBean.base.authority_category);
        tvName.setText("职权名称：" + detailBean.base.authority_name);
        tvCode.setText("职权编码：" + detailBean.base.authority_code);
        tvDepartment.setText("具体实施部门：" + detailBean.base.put_section);
        tvTitle.setText(detailBean.base.title);
    }
}
